package com.cyandpos.pad.cateringformat.morefunction.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.cyandpos.pad.R;
import com.cyandpos.pad.cateringformat.morefunction.bean.Table;
import com.cyandpos.pad.pay.adapter.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

public class CleartableGridAdapter extends BaseAdapter {

    private Context context;
    private List<Table> skfs = new ArrayList<>();
    private int clickTemp = -1;//标识被选择的item
    private int[] clicked;
    private boolean mFlag;
    private boolean isMore=true;
    public CleartableGridAdapter(Context mContext,  List<Table> mSkfs) {
        super();
        this.context = mContext;
        this.skfs = mSkfs;
    }

    @Override
    public int getCount() {
        return skfs.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null){
            convertView = LayoutInflater.from(context).inflate
                    (R.layout.grid_orderfood_table_item, parent, false);
        }

        TextView tv = BaseViewHolder.get(convertView, R.id.grid_item);
        tv.setText(skfs.get(position).getName());
       tv.setText(getStatusSize(skfs.get(position).getSize())+"-"+skfs.get(position).getId()+"-"+skfs.get(position).getStatus());
      //  tv.setTextColor(context.getResources().getColor(R.color.main_title_text));

        if(clickTemp==position){    //根据点击的Item当前状态设置背景
            if(mFlag){
                tv.setTextColor(context.getResources().getColor(R.color.white) );
                tv.setBackgroundResource(R.drawable.pay_item_bg_true);
            }else if(!mFlag){
                tv.setTextColor(context.getResources().getColor(R.color.main_title_text) );
                tv.setBackgroundResource(R.drawable.pay_item_bg_false);
            }
        }else{
            tv.setTextColor(context.getResources().getColor(R.color.main_title_text) );
            tv.setBackgroundResource(R.drawable.pay_item_bg_false);
        }
        return convertView;
    }
    public void setSelectPos(int position,boolean flag) {
        clickTemp = position;
        mFlag = flag;
        notifyDataSetChanged();
    }


    private String getStatusSize(int size) {
        if (size == -1)
            return "特殊桌台";
        else if(size==0)
            return "空置";

        else if(size==1)
            return "一人桌";

        else if(size==2)
            return "二人桌";

        else if(size==3)
            return "三人桌";

        else if(size==4)
            return "四人桌";

        else if(size==5)
            return "五人桌";
        else if(size==6)
            return "六人桌";
        else if(size==7)
            return "七人桌";
        else if(size==8)
            return "八人桌";
        else if(size==9)
            return "九人桌";
        else if(size==10)
            return "十人桌";
        else
            return size+"人桌";

    }

}
